package com.trust.pams.service.redis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

@Configuration
public class PubSubConfig {

    /**
     * 任务频道名
     */
    public static final String CAPTCHA_TOPIC = "pams-quote:captcha-topic";
    /**
     * 收件人队列
     */
    public static final String CAPTCHA_MAIL_QUEEN = "pams-quote:captcha-queen";

    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory , MessageListenerAdapter listenerAdapter){
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory( connectionFactory );
        container.addMessageListener( listenerAdapter , new PatternTopic( CAPTCHA_TOPIC ));
        return container;
    }
}
